package com.edu.method;

import javax.swing.plaf.synth.SynthLookAndFeel;
import java.util.Scanner;

public class MethodDemo {
    public static void main(String[] args) {
        int[] b={22,33,44,55,66,78,23,45};
        int[] c={1,2,3,4};
        int[] d={1,2,3,4};
        int[] e={2,1,3,4};
        int[] g={123,234};
        change(g);
        System.out.println("数组中最大数字是"+getArrayMaxNum(b));
        print(b);
        System.out.println();
        System.out.println(compare(c,d));
        System.out.println(compare(d,e));
        //方法案例
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入数字n--------");

        int a=scanner.nextInt();
        fire(scanner.nextInt(),scanner.nextInt());
        int i=getSum(a);

        jiou(a);

        System.out.println("1-n的和为 "+i);
        int[] array=new int[3];
        System.out.println("请输入需要比较的1三个数");
        for (int j = 0; j < 3; j++) {
            array[j]=scanner.nextInt();
        }
        System.out.println("最大数为"+max(array[0], array[1], array[2]));
    }



    //两个数交换位置
    public static int[] change(int[] a){
        int temp=a[0];
        a[0]=a[1];
        a[1]=temp;
        for (int i = 0; i < 2; i++) {
            System.out.println(a[i]);
        }
        return a;
    }
    //1-n的和
    public static int getSum(int n){
        int sum=0;
        for (int i = 1; i <=n ; i++) {
            sum+=i;
        }
        return sum;
    }
    //判断奇偶数
    public static void jiou(int n){
        if(n%2==0&&n!=0){
            System.out.println("n为偶数");
        }else if(n==0){
            System.out.println("n为0");
        }else if (n%2==1){
            System.out.println("n为奇数");
        }else{
            System.out.println("输入的不为整数");
        }
    }
    //求最值
    public static int max(int a,int b,int c){
        return a>b? (a>c? a:c):(b>c?b:c);
    }
    //数组求最值
    public static int getArrayMaxNum(int[] arr){
        int max=arr[0];
        for (int i = 1; i < arr.length; i++) {
            if(max<arr[i]){
                max=arr[i];
            }else{
                max=max;
            }
        }
        return max;
    }
    //输出数组各元素
    public static void print(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+"\t");
        }
    }
    //判断两个数组是否完全相同
    public static boolean compare(int[] arr1,int[] arr2){
        if(arr1.length==arr2.length){
            for (int i = 0; i < arr1.length; i++) {
                if(arr1[i]!=arr2[i]){
                    return false;
                }
        }
            return true;
        }
        return false;
    }
    //方法的重载
    public static void fire(){
        System.out.println("好好学编程");
    }
    public static void fire(int a){
        System.out.println("好好学编程"+a+"年");
    }
    public static void fire(int a,int b){
        System.out.println("好好学编程"+a+"年，去拿"+b+"元工资");
    }
}
